<?php

/*
 * Контроллер страниц
 */

namespace APPS\PAGES\CONTROLLERS;

use APPS\PAGES\MODELS\Page as PageModel;
use APPS\PAGES\MODELS\PagesTree;

use T4\Exception;

class Page extends \T4\Controller {
    
    /**
     * Отображение отдельной страницы
     */
    public function actionPage() {
	
	$url = $this->parameters->url;
	$page = PageModel::findOneByURL($url);
	
	/**
	 * @todo "Красивую" страницу 404
	 */
	if ( empty($page) ) {
	    header("HTTP/1.1 404 Not Found");
	    header("Status: 404 Not Found");
	    die;
	}
	
	$this->output->page = $page;
	
	$parents = PagesTree::getInstance()->findNodeByID($page->id)->getAllParents();
	foreach ( $parents as &$parent )
	    $parent->url .= '.html';
	
	$this->output->parents = $parents;
	
    }

}